package activity

import (
	"activity_srv/activityclient"
	"api/internal/respons"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGroupLogic {
	return &CreateGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGroupLogic) CreateGroup(req *types.CreateGroupRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	group, err := l.svcCtx.ActivityRpc.CreateGroup(l.ctx, &activityclient.CreateGroupRequest{
		UserId:     req.UserId,
		ProductId:  req.ProductId,
		ProductNum: req.ProductNum,
		GroupType:  req.GroupType,
	})
	if err != nil {
		return respons.Error(400, "拼团创建失败", err.Error()), err
	}
	return respons.Success(group), nil
}
